﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using Monitor.Models.Interfaces;

namespace Monitor.Controllers
{

    [Authorize()]
    public abstract class MainController : Controller
    {
       protected ILogger ErrorLogger;
       public MainController()
       {
           ErrorLogger = DependencyResolver.Current.GetService<ILogger>();
       }

       protected override void OnException(ExceptionContext filterContext)
       {
           ErrorLogger.Fatal(
               string.Format("{0}: {1}", filterContext.Controller.ToString(), filterContext.Exception.Message),
               filterContext.Exception);
           Response.Clear();
           Response.Redirect("~/Error/Unknown");
       }
    }
}
